<template>
    <el-dialog :title="dialogProps.title" :visible.sync="dialogProps.visible" width='400px' append-to-body  :fullscreen = 'Global.currentDevice'>
        <el-form   label-width="150px"  class='mt12'  size='small'  :model='form'  :rules='rules'  ref='form'  :label-position='Global.dialog_label_Position'>
                <el-form-item  label="募集日期"  label-width="80px"  prop='dataTimeYear'>
                      <el-input  v-model.trim="form.dataTimeYear"     class='w-23'   ></el-input> 年 
                      <el-input  v-model.trim="form.dataTimeMonth"    class='w-18'   ></el-input> 月 &nbsp;&nbsp;
                      第  <el-input v-model.trim="form.dataTimeWeek"  class='w-18  mt6'  ></el-input> 周
                </el-form-item>
                <el-form-item  label="本周募集金额(万元)"   prop='weekRaiseAmt'>
                      <el-input  v-model.trim="form.weekRaiseAmt"    type='number'  placeholder='请输入'></el-input>
                </el-form-item>
                <el-form-item  label="本月募集金额(万元)"   prop='monthRaiseAmt'>
                      <el-input  v-model.trim="form.monthRaiseAmt"  type='number'  placeholder='请输入'></el-input>
                </el-form-item>
                <el-form-item  label="累计募集金额(万元)"   prop='totalRaiseAmt'>
                      <el-input  v-model.trim="form.totalRaiseAmt"  type='number'  placeholder='请输入'></el-input>
                </el-form-item>
                <el-form-item  label="已收取挂牌费用(万元)"  prop='listingCharged'>
                      <el-input  v-model.trim="form.listingCharged"  type='number'  placeholder='请输入'></el-input>
                </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
                <el-button @click="dialogProps.visible = false">取 消</el-button>
                <el-button type="primary" @click="submit('form')">确 定</el-button>
        </div>
    </el-dialog>
</template>

<script >
/*interface*/
import  { addCollect,modifyCollect }  from '@/api/professional_work/product/index'

export default {
  name: 'product_AddCollection',
  data() {
    /*validator - 填写日期*/
    let checkDataTime =(rule, value, callback) => {
            if(!this.form.dataTimeYear || !this.form.dataTimeMonth || !this.form.dataTimeWeek){
                  return callback(new Error('请输入时间'));
            }
            else{
              callback();
            }
    };
    return {
      //dialogo基本信息  
      dialogProps: {
        visible: false,
        action: '',
        title: ''
      },

      form:{
          prdCode:'',//当前产品code
          prjCode:'',

          dataTimeYear:'',
          dataTimeMonth:'',
          dataTimeWeek:'',

          weekRaiseAmt:'',
          monthRaiseAmt:'',
          totalRaiseAmt:'',
          listingCharged:'',
      },
      rules:{
            dataTimeYear:[
              // {required:true,message:"请输入时间"},
              { validator: checkDataTime, trigger: 'blur' }
            ],
            weekRaiseAmt:[
              {required:true,message:"请输入本周募集金额"}
            ],
            monthRaiseAmt:[
              {required:true,message:"请输入本月募集金额"}
            ],
            totalRaiseAmt:[
              {required:true,message:"请输入累计募集金额"}
            ],
            listingCharged:[
              {required:true,message:"请输入已收取挂牌费用"}
            ],
      },

      current_code:'',//编辑 code
      isEsit:false,
 
    }
  },
  created(){
    
    
  },
  methods: {
    submit(formName) {
      this.$refs[formName].validate(valid => {
            //通过验证后
              if(valid){
                      if(!this.isEsit){
                          addCollect(this.form).then(res=>{
                            if(res.data.flag == true){
                                this.$message({type:'success',message:res.data.msg})
                                this.$emit('save-finished')
                            }
                          }).catch(error=>{
                            console.log(error)
                          })
                      }
                      else{
                        modifyCollect(this.form).then(res=>{
                          if(res.data.flag == true){
                              this.$message({type:'success',message:res.data.msg})
                              this.$emit('save-finished')
                          }
                        }).catch(error=>{
                          console.log(error)
                        })
                      }
                      
                      this.dialogProps.visible = false
              }
      })
      
    },
  },
  mounted: function() {
    this.$nextTick(() => {
      this.$on('openDialog', function(code,prjCode) {
        this.dialogProps.visible = true
        this.dialogProps.title='添加'

        //重置表单
        this.resetForm('form')

        this.form = {
          code:'',
          prdCode:code,
          prjCode:prjCode,
          dataTimeYear:'',
          dataTimeMonth:'',
          dataTimeWeek:'',
          weekRaiseAmt:'',
          monthRaiseAmt:'',
          totalRaiseAmt:'',
          listingCharged:'',
        }
        this.isEsit = false
      })
      this.$on('openEditDialog', function(row) {
        this.dialogProps.visible = true
        this.dialogProps.title='编辑'

        this.current_code = row.code;

        this.form = {
          code:'',
          prdCode:'',
          prjCode:'',
          dataTimeYear:'',
          dataTimeMonth:'',
          dataTimeWeek:'',
          weekRaiseAmt:'',
          monthRaiseAmt:'',
          totalRaiseAmt:'',
          listingCharged:'',
        };
        [this.form.code,this.form.weekRaiseAmt,this.form.monthRaiseAmt,this.form.totalRaiseAmt,this.form.listingCharged,this.form.dataTimeYear,this.form.dataTimeMonth,this.form.dataTimeWeek,] = [row.code,row.weekRaiseAmt,row.monthRaiseAmt,row.totalRaiseAmt,row.listingCharged,row.dataTimeYear,row.dataTimeMonth,row.dataTimeWeek,]
        this.isEsit = true
      })
    })
  },
  components:{
    
  }
}
</script>

<style  scoped>
</style>


